package com.geek.tutorial.itext.text;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Chunk;
import com.lowagie.text.Font;
import com.lowagie.text.Phrase;


import java.awt.Color;
import java.io.*;

public class Paragraph_Example {

	
	public ByteArrayOutputStream Paragraph_Example() throws Exception{
		
		Document document = new Document();
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
		PdfWriter.getInstance(document, buffer);
		document.open();
		
		Font font = new Font(Font.COURIER, 10, Font.ITALIC);
		font.setColor(new Color(0x92, 0x90, 0x83));
		Chunk chunk = new Chunk("testing text element ", font);
		chunk.setBackground(new Color(0xff, 0xe4, 0x00));
		
		Phrase phrase = new Phrase(30, "This is initial text. "); 
		
		for(int i=0; i < 10; i++)
		{
			phrase.add(chunk); 
		}
		
		Paragraph paragraph = new Paragraph(); // 1
		paragraph.add(phrase); // 2
		
		document.add(paragraph); // 3	
		
		document.add(paragraph); // 4	
		
		document.close();	
                return buffer;
	}
	

	public static void main(String[] args) {
		try{
			Paragraph_Example textExample = new Paragraph_Example();
		}catch(Exception e){
			System.out.println(e);
		}
	}

}